﻿'----------------------------------------------
'   
'   Kernel Info:---------------------------
'   Developer:              Joshua Teeter
'   Genesis:                09-02-08
'   Last Update:            09-06-30
'   Origional Version:      0.1.0.0
'   Current Version:        1.0.0.2
'   ---------------------------------------
'   
'   
'   If you modify this code please leave your name in the modified by list seperated by a comma. 
'   Changes are to be denoted in the following manner:
'                                                       * New
'                                                       ^ Updated
'                                                       - Removed
'                                                       + Added Functionality
'                                                       ! Bug unresolved
'                                                       / Bug resolved
'                                                       % Modified but not changed in a noticeable way in terms of functionality
'  
'  Please use the following as a template and copy and paste as a new comment for each modification.
'   
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            NULL
'   Last Update:            NULL
'   Current Version:        #.#.#.#
'   Changes:                NULL
'   ---------------------------------------
'
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-06
'   Current Version:        0.2.1.3
'   Changes:                 * SMTWTS now has the ability to show the next day without passing values: see tomorrowTime()
'                           ^ Setting interface updated
'                           ^ Changed the font colour for Rocket Launcher title.
'                           ! Known bug when system clock = 00:00 causing application to jump through the list. Meaning really high CPU usage for < 1 sec
'                           / Issue with setting showing 0 to represent 12 resolved
'                           % Added more commenting
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-09
'   Current Version:        0.2.1.4
'   Changes:                 / Issue with no initial list file causing catostrophic failure and unhandled exception. -- Resolved.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-11
'   Current Version:        0.2.1.4p
'   Changes:                 % Changed location for listing file to allow for portablity, just toggle commenting on programFiles var.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-11
'   Current Version:        0.2.1.5
'   Changes:                 / Issue when starting RL that caused strange selection in listbox.
'                           / Fixed issue with drive letter names not showing up (e.g. "C:\" would be "")
'                           % More commenting
'                           % Unified style of commenting.
'                           % Non portable version
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-23
'   Current Version:        0.2.1.6
'   Changes:                 ^ Updated the way shortNames are generated on the fly
'                           ^ Updates to several classes.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-05
'   Current Version:        0.2.1.7
'   Changes:                 ^ Changed the location of the Donate URL
'                           * Added the ability to launch applications on specific days only.
'                           ^ Changed the way that time is loaded into the settings form when editing an application.
'                             The program will now load tomorrows time and tomorrows date if the current time is greater than the launch time.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-25
'   Current Version:        0.2.1.8
'   Changes:                - _engine subroutine is now located in the ATEAList class
'                           * Added scroll bars to navigate up and down on the main list. (They have technically been there the whole time
'                                                                                           but they are now custom).
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-29
'   Current Version:        0.2.1.81
'   Changes:                % There are only minor bug fixes for this version.
'                           - Removed useless imports.
'                           ^ For coders the option Strict should now be set to "ON" when using Rocket Launcher.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-03
'   Current Version:        0.2.1.9
'   External Version:       1.0.0.0
'   Changes:                * You can now skin the main form on rocket launcher!
'                           / Fixed bug when you removed an item it still let you click edit and remove, which would not cause an error.
'                           ^ Changed the "Run at Startup" item to be "ON" by default
'                           * You can now change the default start location of rocket launcher, 
'                               for users who do not have a task bar on the bottom.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-27
'   Current Version:        0.2.2.0
'   External Version:       1.0.0.1
'   Changes:                * Added the ability to start programs at windows start-up via a batch file.
'                           * Added threading to several areas of the data structure.
'                           * Added a minimize button to the top 5 pixels of the main form, that streches along the top.
'                           ^ The form will now hide its self on initial load (psudo).
'                           ^ Lowered the number of calls to disk by Rocket Launcher.
'                           / Fixed a bug with the settings and about forms being closed causing the application to crash
'                             in a very messy way.
'                           / Fixed a bug that would cause Rocket Launcher to show its main form if you had other forms open.
'                           / Fixed major bug caused only on saturday, where Rocket Launcher would try to open the 8th day of the week 
'                           % notifyIcon1 can now be accessed via nIcon which is a private object of the frmMain class.
'                           % Other minor bug fixes
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-30
'   Current Version:        0.2.2.1
'   External Version:       1.0.0.2
'   Changes:                / Removed threading because it caused a major memory leak in rare cases.
'                           ^ Changed the layout slightly to provide more room to applicaton list.
'                           % Other minor bug fixes.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             frmMain.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-07-06
'   Current Version:        0.2.2.2
'   External Version:       1.0.0.3
'   Changes:                / Changed the way that Rocket Launcher will report memory usage, to more accuratly represent
'                             its actual usage.
'   ---------------------------------------
'
'   This application will launch a laundry list of applications or files as defined by the user
'   at times also defined by the user. It is NOT particulary efficent, because of its linear search
'   every second on a growing sorted list of applicaions. However it IS effective.
'
'   Please keep this clean. 
'
'   Thank you to the community of people who faithfully download Rocket Launcher every few weeks!
'
'   Special thanks to my girlfriend Valerie who came up with the name "Rocket Launcher" to replace "Launch" as it was known in alpha.
'
'
'   For readablity "Explicit", and "Strict" options should be on.   
'
'----------------------------------------------
Public Class frmMain

    Private WithEvents nIcon As New System.Windows.Forms.NotifyIcon

    '
    ' Settings file
    '
    Private startPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
    '
    ' Toggle temp and Programfiles variables to make this application portable.
    '
    'Private temp As String = System.Reflection.Assembly.GetExecutingAssembly.Location
    'Private ProgramFiles As String = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, temp.Length - "Rocket Launcher.exe".Length)
    Private ProgramFiles As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)


    Private FileName As String = ProgramFiles & "\RL\list.txt"

    Private SkinFile As String = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, _
                                                                                  System.Reflection.Assembly.GetExecutingAssembly.Location.Length _
                                                                                  - "Rocket Launcher.exe".Length) & "\Skins\" & "default.rls"

    Private themeColors As New Theme

    '
    ' Current process that the time is being changed for.
    '
    Private currentFile As String = ""
    Private currentApp As String = ""
    Private currentArgs As String = ""
    Private mainArray As ATEAList

    Private disabled As Boolean = False
    Private timerVal As Integer = 1000

    '
    ' Array of skins
    '
    Partial Structure SkinStruct
        Dim Path As String
        Dim name As String
    End Structure

    Private Skins As New List(Of SkinStruct)

    Public ReadOnly Property _skinfile_() As String
        Get
            Return SkinFile
        End Get
    End Property

    Public ReadOnly Property _GetSkinColours() As Theme
        Get
            Return themeColors
        End Get
    End Property

    Public Sub loadSkin()
        If My.Settings.SkinPath <> "" Then
            themeColors.OpenSettings(My.Settings.SkinPath)
        Else
            themeColors.OpenSettings(_skinfile_)
        End If
    End Sub


    Public Sub updateArray(ByVal temp As ATEA)

        mainArray.updateArray(temp)

        GC.Collect()

    End Sub

    Public Sub removeFromMainArray(ByRef i As Integer)

        mainArray.RemoveAt(i)

        GC.Collect()

    End Sub

    Public ReadOnly Property _disabled()
        Get
            Return disabled
        End Get
    End Property

    Public Sub SaveToFile()

        mainArray.SaveToFile(ProgramFiles & "\RL", FileName)

        LoadSettings()
        lbLaunchers.DataSource = Nothing
        lbLaunchers.DisplayMember = "_shortName"
        lbLaunchers.DataSource = mainArray

        System.GC.Collect()
    End Sub

    Public Sub LoadSettings()

        lbLaunchers.DataSource = Nothing
        mainArray.Clear()

        mainArray.Open(FileName)

        lbLaunchers.DataSource = Nothing
        lbLaunchers.DisplayMember = "_shortName"
        lbLaunchers.DataSource = mainArray
        nIcon.Icon = My.Resources.MainIcon
        nIcon.ContextMenuStrip = ContextMenuStrip1
        nIcon.Text = "Rocket Launcher " & My.Application.Info.Version.ToString
        nIcon.Visible = True

        System.GC.Collect()
    End Sub

    Private Sub skin()

        '
        ' Arrays for controls on form
        '
        Dim buttons As New List(Of Button)
        Dim labels As New List(Of Label)
        Dim special As New List(Of Label)
        Dim listboxes As New List(Of ListBox)

        '
        ' Add the items to the arrays {
        '
        With buttons
            .Add(btnAddNew)
            .Add(btnClear)
            .Add(btnDown)
            .Add(btnEdit)
            .Add(btnRemove)
            .Add(btnUp)
            .Add(btnMinimize)
        End With

        With labels
            .Add(lblAbout)
            .Add(lblDonate)
        End With

        With special
            .Add(lblTitle)
        End With

        With listboxes
            .Add(lbLaunchers)
        End With
        '
        '}
        '

        '
        ' Get the skin from the file.
        '
        loadSkin()


        '
        ' Set the button values
        '
        For Each btn As Button In buttons

            '
            ' Again using the with command to reduce retyping.
            '
            With btn

                '
                ' Set the background color
                '
                .BackColor = Color.FromArgb(themeColors._colours("btnBRed"), _
                                 themeColors._colours("btnBGre"), _
                                 themeColors._colours("btnBBlu"))

                '
                ' Set the color when the user mouses over the button
                '
                .FlatAppearance.MouseOverBackColor = Color.FromArgb(themeColors._colours("btnMOBRed"), _
                         themeColors._colours("btnMOBGre"), _
                         themeColors._colours("btnMOBBlu"))

                '
                ' Set the color when the user presses the button
                '
                .FlatAppearance.MouseDownBackColor = Color.FromArgb(themeColors._colours("btnMDBRed"), _
                                     themeColors._colours("btnMDBGre"), _
                                     themeColors._colours("btnMDBBlu"))

                '
                ' Set the border color of the button
                '
                .FlatAppearance.BorderColor = Color.FromArgb(themeColors._colours("btnMOBRed"), _
                         themeColors._colours("btnMOBGre"), _
                         themeColors._colours("btnMOBBlu"))

                '
                ' Set the text color
                '
                .ForeColor = Color.FromArgb(themeColors._colours("btnFRed"), _
                                             themeColors._colours("btnFGre"), _
                                             themeColors._colours("btnFBlu"))

            End With

            '
            ' Get the garbage
            '
            GC.Collect()

        Next


        '
        ' Go through all the labels and set the colors
        '
        For Each lbl As Label In labels

            With lbl

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))

                .BackColor = Color.FromArgb(themeColors._colours("lblBRed"), _
                                            themeColors._colours("lblBGre"), _
                                            themeColors._colours("lblBBlu"))

            End With

            GC.Collect()
        Next

        '
        ' This is the title text
        ' 
        For Each specialabel As Label In labels

            With specialabel

                .ForeColor = Color.FromArgb(themeColors._colours("lblSpecialR"), _
                                     themeColors._colours("lblSpecialG"), _
                                     themeColors._colours("lblSpecialB"))
                .BackColor = Color.FromArgb(themeColors._colours("lblBRed"), _
                            themeColors._colours("lblBGre"), _
                            themeColors._colours("lblBBlu"))


            End With
            GC.Collect()
        Next

        '
        ' Set the listbox colors
        '
        For Each lb As ListBox In listboxes

            With lb

                .BackColor = Color.FromArgb(themeColors._colours("lbBRed"), _
                                             themeColors._colours("lbBGre"), _
                                             themeColors._colours("lbBBlu"))

                .ForeColor = Color.FromArgb(themeColors._colours("lbFRed"), _
                                             themeColors._colours("lbFGre"), _
                                             themeColors._colours("lbFBlu"))


            End With
            GC.Collect()
        Next


        '
        ' Set the main form colors
        '
        With Me

            .BackColor = Color.FromArgb(themeColors._colours("frmBRed"), _
                                             themeColors._colours("frmBGre"), _
                                             themeColors._colours("frmBBlu"))

            .ForeColor = Color.FromArgb(themeColors._colours("frmFRed"), _
                                             themeColors._colours("frmFGre"), _
                                             themeColors._colours("frmFBlu"))



            GC.Collect()
        End With
        My.Settings.transparent = CDbl(themeColors._colours("Transparent"))
        MemoryManagement.FlushMemory()
    End Sub

    Private Sub getSkins()

        Dim defaultPath As String = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, _
                                                                                  System.Reflection.Assembly.GetExecutingAssembly.Location.Length _
                                                                                  - "Rocket Launcher.exe".Length) & "\Skins"

        For Each file As String In System.IO.Directory.GetFiles(defaultPath)

            Dim temp As New SkinStruct
            Dim split() As String = file.Split("\"c)

            temp.name = split(split.Count - 1)
            temp.Path = file

            Skins.Add(temp)

            Skinmenu.Items.Add(Name)


        Next

        GC.Collect()

    End Sub


    '
    ' This function sets the location of the form.
    '
    Private Sub position(ByVal pos As String)

        If pos = "br" Then
            My.Settings.PositionX = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - Me.Width
            My.Settings.PositionY = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - Me.Height
            My.Settings.PositionRealitive = "br"

            Me.Location = New Point(My.Settings.PositionX, My.Settings.PositionY)

            BottomLeftToolStripMenuItem1.Checked = False
            BottomRightToolStripMenuItem1.Checked = True
            TopRightToolStripMenuItem1.Checked = False

        ElseIf pos = "bl" Then
            My.Settings.PositionX = My.Computer.Screen.Bounds.Width - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width
            My.Settings.PositionY = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - Me.Height
            My.Settings.PositionRealitive = "bl"

            Me.Location = New Point(My.Settings.PositionX, My.Settings.PositionY)

            BottomLeftToolStripMenuItem1.Checked = True
            BottomRightToolStripMenuItem1.Checked = False
            TopRightToolStripMenuItem1.Checked = False

        Else
            My.Settings.PositionX = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - Me.Width
            My.Settings.PositionY = My.Computer.Screen.Bounds.Height - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height
            My.Settings.PositionRealitive = "tr"

            Me.Location = New Point(My.Settings.PositionX, My.Settings.PositionY)

            BottomLeftToolStripMenuItem1.Checked = False
            BottomRightToolStripMenuItem1.Checked = False
            TopRightToolStripMenuItem1.Checked = True
        End If
        My.Settings.Save()
        GC.Collect()
    End Sub

    '
    ' This is an important subroutine that will purge the batch file if there have been outside changes.
    '
    Private Sub batchSecurity()

        Try
            Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
            Dim batchFileName As String = My.Settings.batchFileName

            If Not StartupFolder.EndsWith("\"c) Then

                StartupFolder &= "\"

            End If

            batchFileName = StartupFolder & batchFileName


            If My.Computer.FileSystem.GetFileInfo(batchFileName).Length <= 135 _
            Or My.Computer.FileSystem.GetFileInfo(batchFileName).Length <> My.Settings.batchFileSize Then

                System.IO.File.Delete(batchFileName)
                mainArray.makeBatch()

            End If
        Catch

        End Try


    End Sub

    '/\ Functions and subs
    '---------------------------------------------------------------------------------------------------
    '\/ Action listeners and small subs

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

        mainArray = New ATEAList()

        Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
        Dim filePath As String = StartupFolder & "\Rocket Launcher.lnk"

        If System.IO.File.Exists(filePath) Then

            StartWithWindowsToolStripMenuItem.Checked = True

        End If


        '
        ' Setup the timer and the interval to be ~1 second and initialize the clock.
        '
        Timer1.Interval = timerVal
        Timer1.Start()

        '
        ' Remove the broder and set the start location to the botton right of any screen.
        '
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

        If (CInt(My.Settings.PositionX) = CInt(0) And CInt(My.Settings.PositionY) = CInt(0)) Then

            My.Settings.PositionRealitive = "br"
            position(My.Settings.PositionRealitive)

        Else


            position(My.Settings.PositionRealitive)


        End If


        '
        ' Define the thread
        '
        Dim skinThread As Threading.Thread
        Dim TStart As New Threading.ThreadStart(AddressOf skin)


        '
        ' Make a new thread
        '
        skinThread = New Threading.Thread(TStart)


        '
        ' Create settings.
        '
        skinThread.Priority = Threading.ThreadPriority.Normal
        skinThread.IsBackground = True


        '
        ' Start the thread.
        '
        skinThread.Start()


        '
        ' setup buttons and time groupbox
        '
        btnRemove.Enabled = False
        btnClear.Enabled = False
        btnEdit.Enabled = False

        nIcon.Text = "Rocket Launcher " & My.Application.Info.Version.ToString


        lbLaunchers.SelectedIndex = -1

        btnRemove.Enabled = False
        btnEdit.Enabled = False

        pnlupdwn.Hide()

        If lbLaunchers.Items.Count >= 9 Then
            pnlupdwn.Show()
        End If

        mainArray.makeBatch()
        Me.Opacity = 0
        Me.Enabled = False
        Me.Hide()

        System.GC.Collect()

    End Sub

    '
    ' Load the form.
    '
    Private Sub frmMain_show(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Shown
        ShowToolStripMenuItem.Enabled = True
        ToolStripMenuItem1.Enabled = True
        Me.Enabled = True
        LoadSettings()

        pnlupdwn.Hide()

        If lbLaunchers.Items.Count >= 8 Then
            pnlupdwn.Show()
        End If

        SaveToFile()
        lbLaunchers.SelectedIndex = -1

        btnRemove.Enabled = False
        btnEdit.Enabled = False
        System.GC.Collect()

    End Sub

    '
    ' Removes selection from the listbox
    '
    Private Sub frmMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click, lblTitle.Click

        lbLaunchers.SelectedIndex = -1
        btnRemove.Enabled = False
        btnEdit.Enabled = False
        GC.Collect()
    End Sub

    '
    ' The timer will call the engine which actually does the work.
    '
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        mainArray._engine()
        GC.Collect()

    End Sub

    Private Sub minimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinimize.Click
        GC.Collect()
        SaveToFile()
        batchSecurity()
        MemoryManagement.FlushMemory()

        Me.Hide()

        System.GC.Collect()
    End Sub

    '
    ' Form is being hidden....
    '
    Private Sub Form1_deactivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Deactivate


        GC.Collect()
        SaveToFile()
        Me.TopMost = False
        batchSecurity()
        Me.Hide()

        System.GC.Collect()

        MemoryManagement.FlushMemory()

    End Sub

    '
    ' Open the window
    '
    Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.Click
        Try
            If Not Setting.Visible And Not About.Visible Then
                '
                ' Open frmMain
                '
                mainArray.Clear()
                mainArray.Open(FileName)
                lbLaunchers.DataSource = Nothing
                lbLaunchers.DisplayMember = "_shortName"
                lbLaunchers.DataSource = mainArray
                Me.Show()
                Me.Opacity = CDbl(My.Settings.transparent) / 100
                Me.Focus()
            End If
        Catch
            '
            ' Open frmMain
            '
            mainArray.Clear()
            mainArray.Open(FileName)
            lbLaunchers.DataSource = Nothing
            lbLaunchers.DisplayMember = "_shortName"
            lbLaunchers.DataSource = mainArray
            Me.Show()
            Me.Opacity = CDbl(My.Settings.transparent) / 100
            Me.Focus()
        End Try



        GC.Collect()

    End Sub

    '
    ' Tool strip start with windows
    '
    Private Sub StartWithWindowsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartWithWindowsToolStripMenuItem.CheckedChanged
        Try

            Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)

            Dim filePath As String = StartupFolder & "\Rocket Launcher.lnk"

            If StartWithWindowsToolStripMenuItem.Checked Then

                Dim WshShell As IWshRuntimeLibrary.WshShellClass = New IWshRuntimeLibrary.WshShellClass

                Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut



                ' The shortcut will be created in the Startup folder

                MyShortcut = CType(WshShell.CreateShortcut(filePath), IWshRuntimeLibrary.IWshShortcut)

                'Specify target file full path

                MyShortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly.Location

                ' e.g.  MyShortcut.TargetPath = "C:\WINDOWS\system32\calc.exe"

                MyShortcut.Save()

            Else
                If IO.File.Exists(filePath) Then

                    IO.File.Delete(filePath)

                End If

            End If

        Catch ex As Exception

            MsgBox("Rocket Launcher could not create a start menu item", MsgBoxStyle.Critical, "Error!")
            StartWithWindowsToolStripMenuItem.Checked = False

        End Try
        GC.Collect()
    End Sub

    '
    ' Disable launching
    '
    Private Sub lblHalt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HaltLaunchingToolStripMenuItem.Click

        If Not HaltLaunchingToolStripMenuItem.Checked Then
            disabled = False
            lblTitle.Text = "Rocket Launcher"

            Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
            Dim batchFileName As String = My.Settings.batchFileName

            If Not StartupFolder.EndsWith("\"c) Then

                StartupFolder &= "\"

            End If

            batchFileName = StartupFolder & batchFileName

            System.IO.File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\RL\TEMP.txt", batchFileName, True)
            System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\RL\TEMP.txt")

            Timer1.Start()

        Else
            disabled = True
            lblTitle.Text = "RL Disabled"
            Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
            Dim batchFileName As String = My.Settings.batchFileName

            If Not StartupFolder.EndsWith("\"c) Then

                StartupFolder &= "\"

            End If

            batchFileName = StartupFolder & batchFileName

            System.IO.File.Copy(batchFileName, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\RL\TEMP.txt", True)
            System.IO.File.Delete(batchFileName)

            Timer1.Stop()

        End If
        GC.Collect()
    End Sub


    '
    ' Save everything on the way out...
    '
    Private Sub frmMain_closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Closing

        GC.Collect()
        SaveToFile()
        batchSecurity()
        MemoryManagement.FlushMemory()
        System.GC.Collect()
        nIcon.Dispose()

    End Sub

    '
    ' Toolstrip close
    '
    Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click

        '
        ' Quit
        '
        GC.Collect()
        Try
            Setting.Dispose()
            About.Dispose()
        Catch
        End Try
        Try
            About.Dispose()
        Catch
        End Try
        Me.Close()

    End Sub




    Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click

        '
        ' Make sure that the current selection is not -1 and then remove the selection from both applications and times.
        ' Then reset the selections and disable button.
        '
        If lbLaunchers.SelectedIndex <> -1 Then

            mainArray.RemoveAt(lbLaunchers.SelectedIndex)
            ' lbLaunchers.Items.RemoveAt(lbLaunchers.SelectedIndex)

            btnRemove.Enabled = False
            btnEdit.Enabled = False

        End If

        '
        ' If there is nothing in the list then disable the button
        '
        If lbLaunchers.Items.Count = 0 Then

            btnClear.Enabled = False

        End If

        lbLaunchers.DataSource = Nothing
        lbLaunchers.DisplayMember = "_shortName"
        lbLaunchers.DataSource = mainArray
        lbLaunchers.SelectedIndex = -1

        If pnlupdwn.Visible Then
            pnlupdwn.Hide()
        End If


        If lbLaunchers.Items.Count >= 9 Then
            pnlupdwn.Show()
        End If

        '
        ' Disable the time setting box
        '
        nIcon.Text = "Rocket Launcher " & My.Application.Info.Version.ToString
        btnRemove.Enabled = False
        btnEdit.Enabled = False
        Me.Refresh()
        System.GC.Collect()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Dim i As Integer

        i = MsgBox("Are you sure you want to clear all data? This will erase all saved data too!", MsgBoxStyle.YesNo, "Rocket Launcher is asking a quetion!")

        If i = MsgBoxResult.Yes Then
            '
            ' Reset the window in all aspects.
            '
            lbLaunchers.Items.Clear()
            mainArray.Clear()
            lbLaunchers.DataSource = Nothing
            lbLaunchers.DisplayMember = "_shortName"
            lbLaunchers.DataSource = mainArray
            lbLaunchers.SelectedIndex = -1

            btnRemove.Enabled = False
            btnEdit.Enabled = False
            pnlupdwn.Dispose()
            SaveToFile()
        Else
            If My.Settings.Egg = 2 Then

                My.Settings.Egg = 3

            End If
        End If
        Me.Show()
        System.GC.Collect()
    End Sub



    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        '
        ' String for the time.
        '
        Dim TimeString As String
        '
        ' Setup the array to split the string
        '
        Dim SplitT() As String
        '
        ' If the user selects an item then load the time from the times listbox into the time selector box and 
        ' enable the box. (Iff the user actually selected an item).
        '
        If lbLaunchers.SelectedIndex <> -1 Then

            Setting.tempArg = mainArray(lbLaunchers.SelectedIndex)._arguements
            Setting.tempName = mainArray(lbLaunchers.SelectedIndex)._application
            Setting.tempTime = mainArray(lbLaunchers.SelectedIndex)._time
            Setting.tempEnabled = mainArray(lbLaunchers.SelectedIndex)._Enabled
            If mainArray(lbLaunchers.SelectedIndex)._StartUp Then

                With Setting
                    .Width = 311
                    .cbEnabled.Enabled = False
                    .cbEnabled.Checked = True
                    .gbStatus.Hide()
                    .Panel1.Hide()
                    .time = False
                    .btnSet.Enabled = True
                End With

            Else
                Setting.time = True
                Setting.Panel1.Hide()

            End If



            '
            ' Get the current item selected and output to i
            '
            Setting.txtPath.Text = mainArray(lbLaunchers.SelectedIndex)._application.ToString

            '
            ' Set the current file.
            '
            Setting.txtArgs.Text = mainArray(lbLaunchers.SelectedIndex)._arguements


            '
            ' Load the time boxes:
            '                       If the time for today has passed then load tomorrow's time.
            '
            If CDate(mainArray(lbLaunchers.SelectedIndex)._time.todaysTime) > CDate(Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)) Then

                TimeString = mainArray(lbLaunchers.SelectedIndex)._time.todaysTime
                Setting.cbDay.SelectedIndex = Today.DayOfWeek

            Else

                If Today.DayOfWeek + 1 = 7 Then
                    Setting.cbDay.SelectedIndex = 0
                Else
                    Setting.cbDay.SelectedIndex = Today.DayOfWeek + 1
                End If

                TimeString = mainArray(lbLaunchers.SelectedIndex)._time.tomorrowsTime


            End If


            SplitT = TimeString.Split(":"c)


            '
            ' Remove the application and its time
            '
            removeFromMainArray(lbLaunchers.SelectedIndex)
            'lbLaunchers.Items.RemoveAt(lbLaunchers.SelectedIndex)
            Setting.Show()

        End If
        btnEdit.Enabled = False
        System.GC.Collect()
    End Sub

    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        Setting.Width = 311
        Setting.Panel1.Show()
        Setting.btnSet.Enabled = False
        Setting.gbStatus.Hide()
        Setting.Show()
        System.GC.Collect()

    End Sub

    Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
        If lbLaunchers.SelectedIndex < lbLaunchers.Items.Count - 1 Then
            btnUp.Enabled = True
            lbLaunchers.SelectedIndex += 1
        End If
        If lbLaunchers.SelectedIndex = lbLaunchers.Items.Count - 1 Then
            btnDown.Enabled = False
        End If
        System.GC.Collect()
    End Sub

    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
        If lbLaunchers.SelectedIndex > -1 Then
            btnDown.Enabled = True
            lbLaunchers.SelectedIndex -= 1
        End If
        If lbLaunchers.SelectedIndex = 0 Then
            btnUp.Enabled = False
        End If
        System.GC.Collect()
    End Sub

    Private Sub lbLaunchers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbLaunchers.SelectedIndexChanged

        '
        ' If the user selects an item then load the time from the times listbox into the time selector box and 
        ' enable the box. (Iff the user actually selected an item).
        '
        If lbLaunchers.SelectedIndex <> -1 Then

            '
            ' Enable the clear and remove buttons for the user
            '
            btnClear.Enabled = True
            btnRemove.Enabled = True
            btnEdit.Enabled = Enabled


            '
            ' Get the current item selected and output to i
            '
            Dim i As String = lbLaunchers.SelectedItem.ToString
            Dim a As String = mainArray(lbLaunchers.SelectedIndex)._application

            '
            ' Set the current file.
            '
            currentFile = i
            currentApp = a
            currentArgs = mainArray(lbLaunchers.SelectedIndex)._arguements


        End If

        If pnlupdwn.Visible Then
            pnlupdwn.Hide()
        End If


        If lbLaunchers.Items.Count >= 9 Then
            pnlupdwn.Show()
        End If

        If lbLaunchers.SelectedIndex = -1 Or lbLaunchers.SelectedIndex = 0 Then
            btnUp.Enabled = False
        Else
            btnUp.Enabled = True
        End If
        If lbLaunchers.SelectedIndex = lbLaunchers.Items.Count - 1 Then
            btnDown.Enabled = False
        Else
            btnDown.Enabled = True
        End If

        System.GC.Collect()
    End Sub

    Private Sub lbLaunchersitem_dclicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbLaunchers.DoubleClick

        If lbLaunchers.SelectedIndex <> -1 Then
            Try
                System.Diagnostics.Process.Start(mainArray(lbLaunchers.SelectedIndex)._application, _
                                 mainArray(lbLaunchers.SelectedIndex)._arguements)
            Catch

            End Try
            btnRemove.Enabled = False
            lbLaunchers.SelectedIndex = -1
        End If
        GC.Collect()
    End Sub

    Private Sub lbLaunchersitem_keyEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lbLaunchers.KeyDown

        If lbLaunchers.SelectedIndex <> -1 And ((e.KeyCode = Keys.Enter) Or (e.KeyCode = Keys.Return)) Then
            Try
                System.Diagnostics.Process.Start(mainArray(lbLaunchers.SelectedIndex)._application, _
                                                 mainArray(lbLaunchers.SelectedIndex)._arguements)
            Catch

            End Try

            btnRemove.Enabled = False
            btnEdit.Enabled = False
            lbLaunchers.SelectedIndex = -1
        End If

        If ((e.KeyCode = Keys.Escape)) Then
            lbLaunchers.SelectedIndex = -1
            btnRemove.Enabled = False
            btnEdit.Enabled = False
        End If
        GC.Collect()
    End Sub

    Private Sub lblAbout_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblAbout.LinkClicked
        '
        ' Show the about form to the user
        '
        About.ShowDialog()
        GC.Collect()
    End Sub

    Private Sub NotifyIcon1_MousedClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles nIcon.MouseDoubleClick
        Me.Show()
        lbLaunchers.SelectedIndex = -1
        btnRemove.Enabled = False
        btnEdit.Enabled = False
        Me.Opacity = CDbl(My.Settings.transparent) / 100
        lblTitle.Focus()
        System.GC.Collect()
    End Sub

    '
    ' Donate link
    '
    Private Sub lblDonate_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblDonate.LinkClicked

        Dim a As Integer

        a = MsgBox("This will open a new browser window at the following address" & vbCrLf _
                   & "http://sourceforge.net/project/project_donations.php?group_id=259423", _
               MsgBoxStyle.OkCancel, "Thank you!")

        If a = MsgBoxResult.Ok Then

            System.Diagnostics.Process.Start("http://sourceforge.net/project/project_donations.php?group_id=259423")
            If My.Settings.Egg = 1 Then

                My.Settings.Egg += 1

            End If
        Else

            Me.Show()

        End If

        GC.Collect()
    End Sub

    Private Sub SetSkinToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetSkinToolStripMenuItem.Click
        ofdSkin.CheckPathExists = True
        ofdSkin.AddExtension = True
        ofdSkin.DefaultExt = ".rls"
        ofdSkin.Filter() = "Rocket Launcher Skin Files (*.rls)|*.rls"
        ofdSkin.Title = "Please select a skin..."
        ofdSkin.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, _
                                                                                  System.Reflection.Assembly.GetExecutingAssembly.Location.Length _
                                                                                  - "Rocket Launcher.exe".Length) & "\Skins"
        ofdSkin.ShowDialog()
        GC.Collect()
    End Sub

    Private Sub ofdSkin_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdSkin.FileOk
        SkinFile = ofdSkin.FileName
        My.Settings.SkinPath = SkinFile
        skin()
    End Sub

    Private Sub BottomRightToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BottomRightToolStripMenuItem1.Click
        position("br")
    End Sub

    Private Sub BottomLeftToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BottomLeftToolStripMenuItem1.Click
        position("bl")
    End Sub

    Private Sub TopRightToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopRightToolStripMenuItem1.Click
        position("tr")
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class
